package cn.com.dcsgo.controller;

import cn.com.dcsgo.dto.BindPhoneDTO;
import cn.com.dcsgo.dto.SendVerificationCodeDTO;
import cn.com.dcsgo.model.Result;
import cn.com.dcsgo.service.MemberService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 短信相关接口
 *
 * @author Dcsgo
 * @since 2025/11/10 13:20
 */
@Tag(name = "短信相关接口")
@RestController
@RequestMapping("p/sms")
public class ShortMessageController {
    @Resource
    private MemberService memberService;

    @PostMapping("send")
    @Operation(summary = "发送绑定手机号验证码",description = "一分钟内只能发一次，有效期3分钟")
    public Result<String> sendSms(@Validated @RequestBody SendVerificationCodeDTO sendVerificationCodeDTO) {
        memberService.sendPhoneCode(sendVerificationCodeDTO);
        return Result.success("发送成功，请注意查看手机短信");
    }

    @PostMapping("savePhone")
    @Operation(summary = "绑定手机号")
    public Result<Void> bindPhone(@Validated @RequestBody BindPhoneDTO bindPhoneDTO){
        return Result.handle(memberService.bindPhone(bindPhoneDTO));
    }
}
